package com.lz.behavior.vistor;

import com.lz.behavior.vistor.ext.DepartmentHeadVisor;

import java.util.Arrays;
import java.util.List;

/**
 * App..
 *
 * @author Lizhong
 * @date 2019/9/27
 */
public class App {
    public static void main(String[] args) {
        Vistor ceoVistor = new CEOVistor();
        Vistor ctoVistor = new CTOVistor();
        Company a = new Manager("A");
        Company b = new Manager("B");
        Company c = new Manager("C");

        Company developor1 = new Developor("1");
        Company developor2 = new Developor("2");
        Company developor3 = new Developor("3");

        List<Company> companies = Arrays.asList(a, b, c, developor1, developor2, developor3);

        System.out.println("CEO考核开始");
        for (Company company : companies) {
            convert(ceoVistor, company);

        }
        System.out.println("CTO考核开始");
        for (Company company : companies) {
            convert(ctoVistor, company);
        }
        // 扩展一个visotor
        System.out.println("department Head 只关注数量");
        DepartmentHeadVisor departmentHeadVisor = new DepartmentHeadVisor();
        for (Company company : companies) {
            convert(departmentHeadVisor, company);
        }
    }

    private static void convert(Vistor ceoVistor, Company company) {
        if (company instanceof Manager) {
            ceoVistor.visit((Manager) company);
        } else if (company instanceof Developor) {
            ceoVistor.visit((Developor) company);
        }
    }
}
